﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace grounding.parser.Parsers
{
    public class DemoActionTemplate : ILogicElement
    {

        #region static stuff
        public static DemoActionTemplate Walking
        {
            get
            {
                DemoActionTemplate retval = new DemoActionTemplate();
                retval.info.Add("direction", null);
                retval.info.Add("distance", null);
                retval.templateOptions.Add("direction", new HashSet<string>(new string[] { "forward", "back", "backward", "left", "right" }));
                retval.templateOptions.Add("distance", new HashSet<string>(new string[] { "one", "two", "three", "four", "five", "six", "seven", 
                    "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen", "twenty" }));
                retval.Type = "walking";
                return retval;
            }
        }

        public static DemoActionTemplate RaiseArms
        {
            get
            {
                DemoActionTemplate retval = new DemoActionTemplate();
                retval.info.Add("arm", null);
                retval.templateOptions.Add("arm", new HashSet<string>(new String[] {"left", "right", "both"}));
                retval.Type = "raiseArms";
                return retval;
            }
        }

        public static DemoActionTemplate CloseHands
        {
            get
            {
                DemoActionTemplate retval = new DemoActionTemplate();
                retval.info.Add("hand", null);
                retval.templateOptions.Add("hand", new HashSet<string>(new String[] { "left", "right", "both" }));
                retval.Type = "closeHands";
                return retval;
            }

        }

        public static DemoActionTemplate OpenHands
        {
            get
            {
                DemoActionTemplate retval = new DemoActionTemplate();
                retval.info.Add("hand", null);
                retval.templateOptions.Add("hand", new HashSet<string>(new String[] { "left", "right", "both" }));
                retval.Type = "openHands";
                return retval;
            }
        }

        public static DemoActionTemplate Unstiff
        {
            get
            {
                DemoActionTemplate retval = new DemoActionTemplate();
                retval.Type = "unstiff";
                return retval;
            }
        }

        public static DemoActionTemplate Stiff
        {
            get
            {
                DemoActionTemplate retval = new DemoActionTemplate();
                retval.Type = "stiff";
                return retval;
            }
        }

        /*
        public static DemoActionTemplate Waving
        {
            get
            {
                //TODO this is terrible and should not be in a method, but we are
                // having weird compiler issues so it's here
                string[] numbers =
                    new string[]{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};

                DemoActionTemplate retval = new DemoActionTemplate();
                retval.info.Add("repititions", null);
                //retval.info.Add("side", null);
                HashSet<string> times = new HashSet<string>(new string[] { "once", "twice" });
                foreach (string number in numbers) {
                    // accept "time" or "times" for all numbers, since we don't care about
                    // actually being super-grammatically correct
                    times.Add(number + " time");
                    times.Add(number + " times");
                }
                retval.templateOptions.Add("repetitions", times);
                //retval.templateOptions.Add("side", new HashSet<string>(new string[] { "left", "right" }));
                retval.Type = "waving";
                return retval;
            }
        }
        */
        #endregion

        public Dictionary<string, string> info = new Dictionary<string, string>();
        private Dictionary<string, HashSet<string>> templateOptions = new Dictionary<string, HashSet<string>>();
        public string Type { get; set; }

        public void FillTemplate(string phrase, bool clarifying = false)
        {
            foreach (string templateField in templateOptions.Keys)
            {
                foreach (string option in templateOptions[templateField])
                {
                    if (phrase.Contains(option))
                    {
                        if (!(clarifying && info[templateField] != null))
                        {
                            Console.WriteLine(templateField + " now is \"" + option + "\"");
                            info[templateField] = option;
                        }
                    }
                }
            }
        }

        public void Clear()
        {
            foreach (string key in info.Keys)
            {
                info[key] = null;
            }
            //info = new Dictionary<string, string>();
        }

        #region ILogicElement Members

        public string Element
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        
        public int Identifier
        {
            get { throw new NotImplementedException(); }
        }

        #endregion
    }
}
